/**
 * 设置执行人 数据初始化
 * @param data 执行人设置数据
 * @param activities 执行规则设置中可选流程环节
 * @param assignerActivitys 执行规则设置中已选中流程环节
 * @param text 当前选中环节名称
 * @param acter 备选人的设置
 * @param doRule 多人处理规则的选定
 * @author Xuejw 2016-11-10
 */

function setActorDataInit(data,activities,assignerActivitys,text,acter,doRule){
	/*初始化树上数据的勾选*/
	var sel_Datas;
	if(data !="" && data.substring(0,1) == "0"){//无数据 时的默认选项
		sel_Datas = data.substring(2, data.length);
		$("#sel_type").val("per");
	}else if(data !="" && data.substring(0,1) == "1"){//按部门和角色
		var deptData = data.substring(2, data.length);
		sel_Datas = deptData.split(";")[0];
		var sel_RoldIds = deptData.split(";")[1];
		var sel_Role = sel_RoldIds.substring(2, data.length);
		$("#role_checked").val(sel_Role);
		$("#sel_type").val("dep");
	}else if(data !="" && data.substring(0,2) == "-4"){//按发起人
		sel_Datas = data;
		$("#sel_type").val("starterWay");
	}else if(data !="" && data.substring(0,2) == "-5"){//按提交人
		sel_Datas = data;
		$("#sel_type").val("fromWay");
	}else{//按具体人
		$("#sel_type").val("per");
	}
	$("#sel_data").val(sel_Datas);//初始化选中的数据
	
	
	//清除掉哪个环节中的内容
	$('#activities > input').remove();
	$('#activities > span').remove();
	var act_data = null;
	if(assignerActivitys!="" && assignerActivitys != null){
		act_data = assignerActivitys.split(",");
	}
	for ( var _i in activities) {
		if (activities[_i]) {
			if(activities[_i].type()=="task" && activities[_i].text() != text){
				var isCheck_act = false;
				if(act_data!=null){
					for(var i=0;i<act_data.length;i++){
						if(act_data[i] == activities[_i].text()){ 
							isCheck_act = true;
						}
					}
				}
				if(isCheck_act){		
					$('#activities').append('<input name="activitys" type="checkbox" value="'+activities[_i].text()+'" checked="checked"/> &nbsp;<span > '+activities[_i].text()+'</span>');
				}else{
					$('#activities').append('<input name="activitys" type="checkbox" value="'+activities[_i].text()+'"/> &nbsp;<span > '+activities[_i].text()+'</span>');
				}
			}
		}
	}
	
	if(acter !='' && acter !=null){
		if(acter==-1){
			$("input[name='ifOnlyOne'][value='1']").click();
		}else{
			$("input[name='ifOnlyOne'][value='0']").click();
			$("#rulePerNum").val(acter); 						
		}
	}else{
		$("input[name='ifOnlyOne'][value='0']").click();
		$("#rulePerNum").val("1"); 
	}
	
	if(doRule == "unique"){
		$("input[name='moreDeal'][value='unique']").click();
	}else if(doRule == "sequence"){
		$("input[name='moreDeal'][value='sequence']").click();
	}else{
		$("input[name='moreDeal'][value='concurrence']").click();
	}
	icheckPlugin.init($('#setting_rule input')); 
	
	$("#role_checked_startPer").val("");//zhangyong先清空选择的角色20141114
	$("#role_checked_sendPer").val("");//zhangyong先清空选择的角色20141114
	
	icheckPlugin.init($('#setting_actor input[name="flag"]'),{ifChecked:icheckSetting.flagChecked});
	
	/**
	 * 根据sel_type值 触发flagChecked事件
	 */
	if($("#sel_type").val() == "per"){
		$("input[name='flag'][value='perWay']").iCheck("check");
	}else if($("#sel_type").val() == "dep"){
		$("input[name='flag'][value='dArWay']").iCheck("check");
	}else if($("#sel_type").val() == "starterWay"){
		$("input[name='flag'][value='starterWay']").iCheck("check");
	}else if($("#sel_type").val() == "fromWay"){
		$("input[name='flag'][value='fromWay']").iCheck("check");
	}
}
/**
 * 设置分支条件 数据初始化
 * @param data 分支条件 数据
 * @author Xuejw 2016-11-10
 */
function setConditionDataInit(data){
	var type = data.split(":")[0];
	if(type=='num'){
		$("#num_round").val(data.split(":")[1]);
		$("#role_checked_condition").val("");
		$("#msg_Rolecontent_condition").text("");
	}else if(type=='role'){
		$("#num_round").val("");
		var role_round = data.split(":")[1].split("|")[0];
		$("#role_round option[value='"+role_round+"']").attr("selected","selected");
		$("#role_checked_condition").val(data.split(":")[1].split("|")[1]);
		$('#msg_Roletitle_condition').show();//选择的角色
		$('#msg_Rolecontent_condition').show();//选择的角色内容	
	}else{
		$("#num_round").val("");
		$("#role_checked_condition").val("");
		$("#condition_num").click();
		$("#msg_Rolecontent_condition").text("");
	}					
	$("#condition_"+type).click();
	
	icheckPlugin.init($('#myflow_condition_setting input'),{ifChecked:icheckSetting.flagChecked}); 
}
//========================初始化结束=========================================================

/**
 * 界面布局控制
 */
function treeChange(flag) {
	if (flag == 'perWay') {
		$("#sel_type").val("per");
		
		$("div[id*=msg]").hide();
		$('#roleTreeAll').hide();
		$('#startPer').hide();
		$('#sendPer').hide();
		$('#depAndRoleDiv').hide();
		$('#addCode').hide();
		$('#perDiv').show();
		$('#sel').show();//选择人员和角色的 大 Div
		$('#msg_title_dep').hide();//选择的部门
		$('#msg_content_dep').hide();//选择的部门内容
		$('#msg_title_per').show();//选择的人员
		$('#msg_content_per').text("");//选择的人员内容先清空
		$('#msg_content_per').show();//选择的人员内容
		$('#msg_Roletitle').hide();//选择的角色
		$('#msg_Rolecontent').hide();//选择的角色内容
		$('#msg_Roletitle_startPer').hide();//选择的角色
		$('#msg_Rolecontent_startPer').hide();//选择的角色内容		
		
		deptAndPerTree();
	} else if (flag == 'dArWay') {
		$("#sel_type").val("dep");
		
		$("div[id*=msg]").hide();
		$('#startPer').hide();
		$('#sendPer').hide();
		$('#perDiv').hide();
		$('#depAndRoleDiv').show();
		$('#addCode').show();
		$('#sel').show();//选择部门和角色的 大 Div
		$('#msg_title_per').hide();//选择的人员
		$('#msg_content_per').hide();//选择的人员内容
		$('#msg_title_dep').show();//选择的部门
		$('#msg_content_dep').text("");//选择的人员内容先清空
		$('#msg_content_dep').show();//选择的部门内容
		$('#msg_Roletitle').show();//选择的角色
		$('#msg_Rolecontent').show();//选择的角色内容
		$('#msg_Roletitle_startPer').hide();//选择的角色
		$('#msg_Rolecontent_startPer').hide();//选择的角色内容				
		deptTree();
		roleTree();
		$('#roleTreeAll').show();
	} else if (flag == 'starterWay') {
		$("#sel_type").val("starterWay");
		$('#roleTreeAll').hide();
		$('#depAndRoleDiv').hide();
		$('#perDiv').hide();
		$('#sendPer').hide();
		$('#addCode').hide();
		$('#startPer').show();
		$('#sel').hide();//选择部门和角色的 大 Div
		starterWayChange();
	} else if (flag == 'fromWay') {
		$("#sel_type").val("fromWay");
		$('#roleTreeAll').hide();
		$('#depAndRoleDiv').hide();
		$('#perDiv').hide();
		$('#startPer').hide();
		$('#addCode').hide();
		$('#sendPer').show();
		$('#sel').hide();//选择部门和角色的 大 Div
		fromWayChange();
	} else if(flag == 'condition_num'){
		$("#condition_num_div").show();
		$("#condition_role_div").hide();
	} else if(flag == 'condition_role'){
		$("#condition_num_div").hide();
		$("#condition_role_div").show();
	}
};
/**
 * 点击按发起人 的数据处理
 */
function starterWayChange(){
	var starterWay_data = $("#sel_data").val();
	
	icheckPlugin.init($("input[name='startPer']:not([value='5']):not([value='6'])"));
	icheckPlugin.init($("input[name='startPer'][value='5']"),{ifChecked:icheckSetting.roleChecked,ifUnchecked:icheckSetting.dealUnChecked});
	icheckPlugin.init($("input[name='startPer'][value='6']"),{ifChecked:icheckSetting.perChecked,ifUnchecked:icheckSetting.dealUnChecked});
	
	if(starterWay_data !="" && starterWay_data.substring(0,2) == "-4"){
		var data = starterWay_data.substring(3,4);
		//初始选择第一项
		$("input[name='startPer'][value='0']").iCheck("check");
		
		if(data == "1"){
			$("input[name='startPer'][value='1']").iCheck("check");
		}else if(data == "2"){
			var startSel = starterWay_data.substring(5,6);
			$("#startSel").val(startSel);
			$("input[name='startPer'][value='2']").iCheck("check");
		}else if(data == "3"){
			$("input[name='startPer'][value='3']").iCheck("check");
		}else if(data == "4"){
			$("input[name='startPer'][value='4']").iCheck("check");
		}else if(data == "5"){
			$("#role_checked_startPer").val(starterWay_data.substring(5));
			$("input[name='startPer'][value='5']").iCheck("check");
		}else if(data == "6"){			
			var startSel = starterWay_data.substring(5);
			$("#per_selected_startPer").val(startSel);
			$("input[name='startPer'][value='6']").iCheck("check");
		}
	}else{
		$("input[name='startPer'][value='0']").iCheck("check");
	}
}
/**
 * 点击按提交人 的数据处理
 */
function fromWayChange(){
	var fromWay_data = $("#sel_data").val();
	
	icheckPlugin.init($("input[name='sendPer']:not([value='6'])"));
	icheckPlugin.init($("input[name='sendPer'][value='6']"),{ifChecked:icheckSetting.roleChecked,ifUnchecked:icheckSetting.dealUnChecked}); 

	if(fromWay_data !="" && fromWay_data.substring(0,2) == "-5"){
		var data = fromWay_data.substring(3,4);
		//初始选择第一项
		$("input[name='sendPer'][value='1']").iCheck("check");
		
		if(data == "2"){
			var sendSel = fromWay_data.substring(5,6);
			$("#sendSel").val(sendSel);
			$("input[name='sendPer'][value='2']").iCheck("check");
		}else if(data == "3"){
			$("input[name='sendPer'][value='3']").iCheck("check");
		}else if(data == "4"){
			$("input[name='sendPer'][value='4']").iCheck("check");
		}else if(data == "5"){
			$("input[name='sendPer'][value='5']").iCheck("check");
		}else if(data == "6"){
			//选择的角色
			var sendSel = fromWay_data.substring(5);
			$("#role_checked_sendPer").val(sendSel);
			$("input[name='sendPer'][value='6']").iCheck("check");
		}
	}else{
		$("input[name='sendPer'][value='1']").iCheck("check");
	}
}


//add by calonlan 加载角色树
function roleTree() {
	$("#msg_Rolecontent").text("");
	$('#roleTree').empty();
	$.ajax({
		type : "POST",
		url : jsBaskPath+"/workflow/perConfig!asynLoadRole.action",
		data : "",
		success : function(msg) {
			var listRoles = eval(msg);
			
			var sel_Role = $("#role_checked").val();
			var sel_Roles = null ;
			if(sel_Role != null && sel_Role != ""){
				sel_Roles = sel_Role.split(",");
			}
			var msg_Rolecontent = "";
			for ( var i = 0; i < listRoles.length; i++) {
				var isCheck = false;
				if(sel_Roles != null){
					for(var j=0;j<sel_Roles.length;j++){
						if(sel_Roles[j] == listRoles[i].id){
							isCheck =true;
						}
					}
				}
				if(isCheck){
					$('#roleTree').append(
									'<input name="roleId" type="checkbox" value ="'
											+ listRoles[i].id + '" checked="checked" /><span id='+ listRoles[i].id+'>&nbsp;&nbsp;'
											+ listRoles[i].name + '</span></br>');
					msg_Rolecontent += listRoles[i].name +",";
				}else{
					$('#roleTree').append(
									'<input name="roleId" type="checkbox" value ="'
											+ listRoles[i].id + '" /><span id='+ listRoles[i].id+'>&nbsp;&nbsp;'
											+ listRoles[i].name + '</span></br>');
				}
				//角色选中 checkbox 初始化
				icheckPlugin.init($('#roleTree input'),{ifChecked:icheckSetting.roleChecked,ifUnchecked:icheckSetting.roleChecked});
			}
			if(msg_Rolecontent != ""){
				$("#msg_Rolecontent").text(msg_Rolecontent.substring(0,msg_Rolecontent.length-1));
			}else{
				$("#msg_Rolecontent").text(msg_Rolecontent);
			}
		}
	});
};

// 执行人的确定
function queding() {
	var roleTree = $("input[name='roleId']");
	var startPerCheck = $("input[name='startPer']:checked").val();
	var sendPerCheck = $("input[name='sendPer']:checked").val();
	var perIds = "0:"; // 人员的id集合
	var deptIds = "1:"; // 部门的id集合
	var roleIds = "2:";// 角色的id集合
	var startPers = "-4:";// 发起人的Id
	var sendPers = "-5:";// 提交人的Id
	var startSel = $('#startSel').val();// 发起人中选择的上几级部门
	var sendSel = $('#sendSel').val();// 提交人中选择的上几级部门
	var selState = $("input[name='flag']:checked").val();
	if(selState == 'perWay'){
		var treeObj = $.fn.zTree.getZTreeObj("tree");
		var orgTree = treeObj.getCheckedNodes(true);
		
		for ( var i = 0; i < orgTree.length; i++) {
			if (orgTree[i].type == 'per') {
				perIds += orgTree[i].id + ",";
			}
		}
		if(perIds.lastIndexOf(',')!=-1){
			perIds = perIds.substring(0,perIds.length-1);
		}
		if(perIds=="0:"){
			return "";
		}
		return perIds;
	}else if(selState == 'dArWay'){
		var deptTreeObj = $.fn.zTree.getZTreeObj("deptTree");
		var deptTree = deptTreeObj.getCheckedNodes(true);
		
		for ( var i = 0; i < deptTree.length; i++) {
			if (deptTree[i].type == 'dep') {
				deptIds += deptTree[i].id + ",";
			}
		}
		for ( var i = 0; i < roleTree.length; i++) {

			if (roleTree[i].checked == true) {
				roleIds += roleTree[i].value + ",";
			}
		}
		if(deptIds.lastIndexOf(',')!=-1){
			deptIds = deptIds.substring(0,deptIds.length-1);
		}
		if(roleIds.lastIndexOf(',')!=-1){
			roleIds = roleIds.substring(0,roleIds.length-1);
		}
		if(deptIds=="1:"&&roleIds=="2:"){
			return "";
		}
		return deptIds + ";" + roleIds;
	}else if(selState == 'starterWay'){
		if(startPerCheck=='2'){//发起人上几级部门负责人
			return startPers + startPerCheck +"|" + startSel;//zhangyong 将,号改成|号
		}else if(startPerCheck=='5'){//发起人部门指定角色zhangyong20141112
			var role_checked_startPer = $("#role_checked_startPer").val();
			//alert("选择的人员"+startPers + startPerCheck+"|"+role_checked_startPer );
			return startPers + startPerCheck+"|"+role_checked_startPer;
		}else if(startPerCheck=='6'){
			var perIds_startPer="";
			var treeObj = $.fn.zTree.getZTreeObj("tree_startPer");
			var orgTree = treeObj.getCheckedNodes(true);			
			for ( var i = 0; i < orgTree.length; i++) {
				if (orgTree[i].type == 'per') {
					perIds_startPer += orgTree[i].id + ",";
				}
			}
			if(perIds_startPer.lastIndexOf(',')!=-1){
				perIds_startPer = perIds_startPer.substring(0,perIds_startPer.length-1);
			}			
			return startPers + startPerCheck+"|"+perIds_startPer;
		}else{
			return startPers + startPerCheck;
		}
	}else if(selState == 'fromWay'){
		if(sendPerCheck == '2'){//提交人上几级部门负责人
			return sendPers + sendPerCheck +"|" + sendSel;
		}else if(sendPerCheck=='6'){//提交人部门指定角色zhangyong20141114
			var role_checked_sendPer = $("#role_checked_sendPer").val();
			//alert("选择的人员"+sendPers + sendPerCheck+"|"+role_checked_sendPer );
			return sendPers + sendPerCheck+"|"+role_checked_sendPer;
		}else{
			return sendPers + sendPerCheck;
		}
	}
	
}

function quedingCondition() {
	var condition_flag = $("input[type='radio'][name='condition_flag']:checked").val();
	if(condition_flag=='condition_num'){
		if($("#num_round").val()){
			return "num:"+$("#num_round").val(); 
		}else{
			return "";
		}
		
	}else if(condition_flag=='condition_role'){
		if($("#role_round").val()&&$("#role_checked_condition").val()){
			return "role:"+$("#role_round").val()+"|"+$("#role_checked_condition").val();
		}else{
			return "";
		}
	}
}

function addPerNum(){
	var curPerNum =  $("#rulePerNum").val();
	$("#rulePerNum").val(curPerNum-0+1);
}
function delPerNum(){
	var curPerNum =  $("#rulePerNum").val();
	if((curPerNum-0)>1){
		$("#rulePerNum").val(curPerNum-1);
	}
}
/**
 * 选择角色
 * @param type
 */
function showRoleContent(type,obj){
	
	$("div[id*=msg]").hide();
	$('#msg_Roletitle_'+type).show();//选择的角色
	$('#msg_Rolecontent_'+type).show();//选择的角色内容	
	
	$("#roleTreeAll_startPer_sendPer").show();
	$("#perDiv_startPer").hide();

	$('#roleTree_startPer_sendPer').empty();
	$("#msg_Rolecontent_"+type).text("");
	
	$.ajax({
		type : "POST",
		url : jsBaskPath+"/workflow/perConfig!asynLoadRole.action",
		data : "",
		async: false,
		success : function(msg) {
			var listRoles = eval(msg);
			
			obj.data("roleData",listRoles);
			
			var sel_Role = $("#role_checked_"+type).val();
			var sel_Roles = null ;
			if(sel_Role != null && sel_Role != ""){
				sel_Roles = sel_Role.split(",");
			}
			var msg_Rolecontent = "";
			for ( var i = 0; i < listRoles.length; i++) {
				var isCheck = false;
				if(sel_Roles != null){
					for(var j=0;j<sel_Roles.length;j++){
						if(sel_Roles[j] == listRoles[i].id){
							isCheck =true;
						}
					}
				}
				var checkStr='';
				if(isCheck){
					msg_Rolecontent += listRoles[i].name +",";
				}												
			}
			if(msg_Rolecontent != ""){
				$("#msg_Rolecontent_"+type).text(msg_Rolecontent.substring(0,msg_Rolecontent.length-1));
			}else{
				$("#msg_Rolecontent_"+type).text(msg_Rolecontent);
			}
		}
	});
}
function showPerContent(type,obj){
	$("div[id*=msg]").hide();
	$('#msg_Pertitle_'+type).show();//选择的角色
	$('#msg_Percontent_'+type).show();//选择的角色内容	
	
	var sel_data = $("#per_selected_startPer").val();//选中的数据	
	$("#roleTreeAll_startPer_sendPer").hide();
	$("#perDiv_startPer").show();
	$("#msg_Percontent_"+type).text("");
	
	$.ajax({			
	    type : "POST",
	    async: false,
	    url : jsBaskPath+"/workflow/perConfig!asynLoadOrgs.action",						
	    data: "selData="+sel_data+"&selType=per",						    									
	    success : function(msg){	
	    	var json = eval( '(' + msg + ')' );
	    	
	    	obj.data("perdata",json);
	    	var msg_content_per = "";
	    	if(json!=null){
		    	for(var i=0;i<json.length;i++){
			    	if (json[i].checked&&json[i].type == 'per') {
						msg_content_per += json[i].name + ",";
					}
		    	}
	    	}
	    	if(msg_content_per != ""){
				$("#msg_Percontent_"+type).text(msg_content_per.substring(0,msg_content_per.length-1));
			}else{
				$("#msg_Percontent_"+type).text(msg_content_per);
			}
	    }		
	});		
}

function showPerTree(type,obj){
	getRoleByPerHtml("选择人员");
	$.fn.zTree.init($("#tree_startPer"),setting,$(obj).data("perdata"));
}
//add by calonlan
function showRoleTree(type,obj){
	getRoleByPerHtml("角色选择");
	
	var listRoles = $(obj).data("roleData");
	
	var sel_Role = $("#role_checked_"+type).val();
	var sel_Roles = null ;
	if(sel_Role != null && sel_Role != ""){
		sel_Roles = sel_Role.split(",");
	}
	if(listRoles){
		for ( var i = 0; i < listRoles.length; i++) {
			var isCheck = false;
			if(sel_Roles != null){
				for(var j=0;j<sel_Roles.length;j++){
					if(sel_Roles[j] == listRoles[i].id){
						isCheck =true;
					}
				}
			}
			var checkStr='';
			if(isCheck){
				checkStr = 'checked="checked"';
			}												
			$('#roleTree_startPer_sendPer').append(
					'<input name="roleId_'+type+'" type="checkbox" value ="'
					+ listRoles[i].id + '" '+checkStr+'/><span id='+ listRoles[i].id+'>&nbsp;&nbsp;'
					+ listRoles[i].name + '</span></br>');
			
		}
	}
	//角色选择
	icheckPlugin.init($('#roleTree_startPer_sendPer input'),{ifChecked:icheckSetting.roleChecked,ifUnchecked:icheckSetting.roleChecked});
}


//点击角色的方法
function checkRole(type){
	var checkedRole = $("input[name='roleId_"+type+"']:checked");
	var roleStr = "";
	var roleIdStr = "";
	for(var i=0;i<checkedRole.length;i++){
		var item = checkedRole[i];
		roleStr += $('#'+$(item).val()).text()+",";
		roleIdStr +=$(item).val()+",";
	}	
	roleStr = roleStr.substring(0,roleStr.length-1);
	roleIdStr= roleIdStr.substring(0,roleIdStr.length-1);
	$("#msg_Rolecontent_"+type).text(roleStr);
	$("#role_checked_"+type).val(roleIdStr);
}
//点击角色的方法
function checkRole_(){
	var checkedRole = $("input[name='roleId']:checked");
	var roleStr = "";
	for(var i=0;i<checkedRole.length;i++){
		var item = checkedRole[i];
		roleStr += $('#'+$(item).val()).text()+",";
	}
	roleStr = roleStr.substring(0,roleStr.length-1);
	$("#msg_Rolecontent").text(roleStr);
}
//选择人或角色显示区内容
function getRoleByPerHtml(title){
	var html='<div id="setting_actor" style="display:block;">'
			//<!-- 人员 div-->
			+'		<div id="perDiv_startPer" class="treePanel">'
			+'			<div id="tree_startPer" class="ztree" ></div>'
			+'		</div>'
			//<!-- 角色的div -->
			+'		<div id="roleTreeAll_startPer_sendPer">'
			+'			<div class="treePanel" id="roleTree_startPer_sendPer" style="padding-left:10px" ></div>'
			+'		</div>'
			+'</div>';
	return dialog.formModal('content:'+html, title,true,false,400);
}
//按具体人查询的数据
function  deptAndPerTree(){
	var sel_data = $("#sel_data").val();//选中的数据
	var sel_type = $("#sel_type").val();//数据类型
	var sel_change = $("#sel_change").val();//选中类型
	$.ajax({			
	    type : "POST",
	    url : jsBaskPath+"/workflow/perConfig!asynLoadOrgs.action",						
	    data: "selData="+sel_data+"&selType="+sel_type+"&selChange="+sel_change,						    									
	    success : function(msg){	
	    	var obj = eval( '(' + msg + ')' );
	    	var perTree = $.fn.zTree.init($("#tree"),setting,obj).getCheckedNodes(true);
	    	var msg_content_per = "";
	    	if(perTree!=null){
		    	for(var i=0;i<perTree.length;i++){
			    	if (perTree[i].type == 'per') {
						msg_content_per += perTree[i].name + ",";
					}
		    	}
	    	}
	    	if(msg_content_per != ""){
				$("#msg_content_per").text(msg_content_per.substring(0,msg_content_per.length-1));
			}else{
				$("#msg_content_per").text(msg_content_per);
			}
	    }		
	});	
}
//按部门和角色查询的数据
function  deptTree(){
	var sel_data = $("#sel_data").val();//选中的数据
	var sel_type = $("#sel_type").val();//数据类型
	var sel_change = $("#sel_change").val();;//选中类型
	$.ajax({			
	    type : "POST",
	    url : jsBaskPath+"/workflow/perConfig!asynLoadDept.action",						
	    data: "selData="+sel_data+"&selType="+sel_type+"&selChange="+sel_change,						    									
	    success : function(msg){	
	    	var obj = eval( '(' + msg + ')' );
	    	var deptTree = $.fn.zTree.init($("#deptTree"),setting,obj).getCheckedNodes(true);
	    	var msg_content_dep = "";
	    	if(deptTree!=null){
		    	for(var i=0;i<deptTree.length;i++){
			    	if (deptTree[i].type == 'dep') {
						msg_content_dep += deptTree[i].name + ",";
					}
		    	}
	    	}
	    	if(msg_content_dep != ""){
				$("#msg_content_dep").text(msg_content_dep.substring(0,msg_content_dep.length-1));
			}else{
				$("#msg_content_dep").text(msg_content_dep);
			}
	    }		
	});	
}
//树结构
var setting = {
	check: {
		enable: true,//需要显示checkbox
		chkStyle: "checkbox",
		chkboxType: { "Y": "s", "N": "s" } //勾选操作，只影响子级节点；取消勾选操作，只影响子级节点
	},
	data: {
		simpleData: {
			enable: true
		}
	},
	callback: {
		onCheck: zTreeOnCheck
	}
};
//回调函数
function zTreeOnCheck(event, treeId, treeNode) {
	var treeObj = $.fn.zTree.getZTreeObj(treeId);
	var orgTree = treeObj.getCheckedNodes(true);
	var msg_content_per = "";
	var msg_content_dep = "";
	var per_selected_startPer="";
	for(var i=0;i<orgTree.length;i++){
		if(treeId == 'tree'||treeId == 'tree_startPer'){
			if(orgTree[i].type == 'per'){
				msg_content_per += orgTree[i].name+",";
				per_selected_startPer += orgTree[i].id+",";
			}
		}else if(treeId == 'deptTree'){
			if(orgTree[i].type == 'dep'){
				msg_content_dep += orgTree[i].name+",";
			}
		}
	}
	if(treeId == 'tree'){
		msg_content_per = msg_content_per.substring(0,msg_content_per.length-1);
		$("#msg_content_per").text(msg_content_per);
	}else if(treeId == 'deptTree'){
		msg_content_dep = msg_content_dep.substring(0,msg_content_dep.length-1);
		$("#msg_content_dep").text(msg_content_dep);		
	}else if(treeId == 'tree_startPer'){
		msg_content_per = msg_content_per.substring(0,msg_content_per.length-1);
		per_selected_startPer = per_selected_startPer.substring(0,per_selected_startPer.length-1);
		$("#msg_Percontent_startPer").text(msg_content_per);		
		$("#per_selected_startPer").val(per_selected_startPer);		
	}
};

/**
 * icheck组件事件处理配置
 * @author Xuejw 2016-11-11
 */
var icheckSetting = {
	/**
	 * 执行人设置类别处理选中事件
	 * @param event
	 */
	flagChecked:function (event){
		if("flag"==event.target.name){
			treeChange(event.target.value);
		}else if("condition_flag"==event.target.name){
			treeChange(event.target.value);
			showRoleContent('condition',$(event.target).parents("#setting_actor").find("button:not([id='conditionSub'])"));
		}
	},	
	/**
	 * 执行人设置 处理取消事件 
	 * @param event
	 */
	dealUnChecked:function (event){
		if("sendPer"==event.target.name){
			$(event.target).parents("p").find("button").attr("disabled","true");
			$('#sel').hide();
		}else if("startPer"==event.target.name){
			$(event.target).parents("p").find("button").attr("disabled","true");
			$('#sel').hide();
		}
	},
	/**
	 * 执行人设置角色 处理选中事件 
	 * @param event
	 */
	roleChecked:function (event){
		if("sendPer"==event.target.name){
			$("#setting_actor button[class*='btn btn-sm']").attr("disabled","true");
			$(event.target).parents("p").find("button").removeAttr("disabled");
			$('#sel').show();
			showRoleContent('sendPer',$(event.target).parents("p").find("button"));
		}else if("roleId_sendPer"==event.target.name){
			checkRole("sendPer");
		}else if("startPer"==event.target.name){
			$("#setting_actor button[class*='btn btn-sm']").attr("disabled","true");
			$(event.target).parents("p").find("button").removeAttr("disabled");
			$('#sel').show();
			showRoleContent('startPer',$(event.target).parents("p").find("button"));
		}else if("roleId_startPer"==event.target.name){
			checkRole("startPer");
		}else if("roleId"==event.target.name){
			checkRole_();
		}else if("roleId_condition"==event.target.name){
			checkRole("condition");
		}
	},
	/**
	 * 执行人设置具体人 处理选中事件 
	 * @param event
	 */
	perChecked:function (event){
		if("startPer"==event.target.name){
			$("#setting_actor button[class*='btn btn-sm']").attr("disabled","true");
			$(event.target).parents("p").find("button").removeAttr("disabled");
			$('#sel').show();//选择部门和角色的 大 Div
			showPerContent('startPer',$(event.target).parents("p").find("button"));
		}
	}
};